import java.util.Arrays;

public class demo2 {

    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("abcdef");
        stringBuilder.insert(3,"haha");
        System.out.println(stringBuilder);
    }

        public static void main19(String[] args) {
            long start = System.currentTimeMillis();
            String s = "";
            for(int i = 0; i < 10000; ++i){
                s += i;
            }
            long end = System.currentTimeMillis();
            System.out.println(end - start);//151

            start = System.currentTimeMillis();
            StringBuffer sbf = new StringBuffer("");
            for(int i = 0; i < 10000; ++i){
                sbf.append(i);
            }
            end = System.currentTimeMillis();
            System.out.println(end - start);//2

            start = System.currentTimeMillis();
            StringBuilder sbd = new StringBuilder();
            for(int i = 0; i < 10000; ++i){
                sbd.append(i);
            }
            end = System.currentTimeMillis();
            System.out.println(end - start);//2
    }

    public static void main8(String[] args) {
        final int array[] = {1,2,3,4,5};
        array[0] = 100;
        System.out.println(Arrays.toString(array));//100,2,3,4,5
    }

    public static void main7(String[] args) {
        String s = "        abc d e   fg   ";
        String s1 = s.trim();//只会去除 左右两边的空格
        System.out.println(s1);//abc d e   fg
    }

    public static void main6(String[] args) {
        String s = "abcdef";
        String s1 = s.substring(2);
        System.out.println(s1);//cdef
        String s2 = s.substring(2,5);//[2,5)
        System.out.println(s2);//cde
        //这里需要注意的是，不包含 5 下标。在Java中范围大部分都是前闭后开
    }

    public static void main5(String[] args) {
        String s = "name=zhangsan&age=10";
        String[] strings = s.split("&|=");
        for (int i = 0; i < strings.length; i++) {
            System.out.print(strings[i] + " ");
        }//name zhangsan age 10
    }

    public static void main4(String[] args) {
        String s = "172.0.0.1";
        String[] strings = s.split(".");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }//这里就什么都输出不出来、
        String[] strings1 = s.split("\\.");
        for (int i = 0; i < strings1.length; i++) {
            System.out.print(strings1[i] + " ");
        }//172 0 0 1
    }

    public static void main3(String[] args) {
        String s = "name=zhangsan&age=10";
        String[] strings = s.split("&");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }// name=zhangsan age=10
        String[] strings1 = s.split("&",1);
        for (int i = 0; i < strings1.length; i++) {
            System.out.println(strings1[i]);
        }//name=zhangsan&age=10
    }

    public static void main2(String[] args) {
        String s = "ababcabcd";
        String tmp = s.replace('a','k');
        System.out.println(tmp);//kbkbckbcd

        tmp = s.replace("ab","uuu");
        System.out.println(tmp);//uuuuuucuuucd

        tmp = s.replaceFirst("ab","uuu");
        System.out.println(tmp);//uuuabcabcd

        tmp = s.replaceAll("ab","ooo");
        System.out.println(tmp);//oooooocooocd
    }

    public static void main1(String[] args) {
        String s2 = String.format("%d,%d,%d",2019,9,9);
        System.out.println(s2);//2019,9,9
    }
}
